package com.happyass.dao;

import com.happyass.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface UserDao extends PagingAndSortingRepository<User,Integer>, JpaRepository<User,Integer> {
    User findByUserName(@Param("userName") String userName);
    //批量删除用户
    @Transactional
    @Modifying(clearAutomatically = true)
    //@Query 定义sql的注解。nativeQuery = true 表示定义是sql语句，false 是定HQL语句
    @Query(value="delete  from user  where user_id in(:userIds)",nativeQuery = true)
    void deleteAllUser(@Param("userIds") List<String> userIds);

}
